package com.module.businessLog;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import base.util.ConstantUnit;
import base.util.Page;
import base.util.StringUtil;

import com.module.businessLog.vo.LogContent;
import com.module.businessLog.vo.LogRecord;
import com.module.sys.LoginSession;
import com.util.IPUtil;

public class BusinessLogService {
	
	public BusinessLogService(){}
	/**
	 * 分页查询编号说明信息
	 * @param log 日志内容对象
	 * @param start 开始分页行
	 * @param limit 每一页的最大行数
	 * @return 对象结果集
	 * @throws Exception
	 */
	 public Page toList(LogContent log,final Integer start,final Integer limit) throws Exception{
		    Page page = new Page();
            page.setStart(start);
            page.setLimit(limit);            
            Map<String,Object> map = new HashMap<String,Object>();
    	    map.put(ConstantUnit.O_PT, "toListLogBusinessLog");
     	    map.put(ConstantUnit.PAGE, page);
     	    map.put("content", log);   
    	    return BusinessSocketClient.returnValue(map).getPage();
		}
	 /**
	  * 添加业务日志
	  * @param content 日志内容对象
	  * @param record 日志序号对象
	  * @return 返回成功或者失败
	 * @throws Exception 
	  */
	 public Map<String,Object> save(LogContent content,String id) throws Exception{
		 LogRecord record = new LogRecord();
		 if(StringUtil.isNull(id)){
			record.setCreateTime(new Date());
			record.setCreateMan(LoginSession.getRolename());
		 }else{
			record.setEditTime(new Date());
			record.setEditMan(LoginSession.getRolename());
		 }
		 record.setIp(IPUtil.getIp());
		 Map<String,Object> map = new HashMap<String,Object>();
	 	    map.put(ConstantUnit.O_PT, "addLogBusinessLog");
	  	    map.put("content", content); 
	  	    map.put("record", record);
		 return BusinessSocketClient.returnValue(map).getResult();
	 }
	 
	/**
	  * 根据ID批量删除
	  * @param idArray ID数组 
	  * @return Map对象
	  * @throws Exception
	  */
	public Map<String,Object>  remove(List<String> idArray) throws Exception{
		String ids = StringUtil.getNewStrByList(idArray);
		LogContent obj = new LogContent();
		obj.setId(ids);	      
		Map<String,Object> map = new HashMap<String,Object>();
		map.put(ConstantUnit.O_PT,"delLogBusinessLog");
		map.put("content", obj);
		return BusinessSocketClient.returnValue(map).getResult();
	}
	
}
